package com.sbeam.service;

import com.sbeam.mapper.InfoMapper;
import com.sbeam.pojo.Info;
import com.sbeam.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class InfoServiceImplement implements InfoService {
    @Autowired
    private InfoMapper infoMapper;
    @Override
    public PageResult getInfoList1(PageResult pageResult) {
        long total=infoMapper.findTotal();
        int size= pageResult.getPageSize();
        int start=(pageResult.getPageNum()-1)*size;
        String query= pageResult.getQuery();
        List<Info> infoList= infoMapper.getInfoList1(start,size,query);
        for (Info info :infoList){
            String[] split = info.getImages().split(",");
            ArrayList<String> strings = new ArrayList<>(Arrays.asList(split));
            info.setImagesList(strings);
        }
        System.out.println(infoList);
        return pageResult.setTotal(total).setRows(infoList);
    }

    @Override
    public void updateLike(Info info) {
        infoMapper.updateLike(info);
    }

    @Override
    public List<Info> getInfo() {
        return infoMapper.getInfo();
    }

    @Override
    public void saveComment(Info info) {
        infoMapper.saveComment(info);
    }


    @Override
    public PageResult getInfoList2(PageResult pageResult) {
        long total=infoMapper.findTotal();
        int size= pageResult.getPageSize();
        int start=(pageResult.getPageNum()-1)*size;
        String query= pageResult.getQuery();
        List<Info> infoList= infoMapper.getInfoList2(start,size,query);
//        for (Info item :infoList){
//            String[] split = item.getImages().split(",");
//            ArrayList<String> strings = new ArrayList<>(Arrays.asList(split));
//            item.setImagesList(strings);
//        }
        return pageResult.setTotal(total).setRows(infoList);
    }


}
